﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Media.Animation;
using System.Windows.Media;
using System.Windows;

namespace ElectricalSymbols.Storyboards
{
	public class OpenStory
	{
		private readonly Storyboard _openStoryBoard = new();
		public OpenStory(UIElement target)
		{
			InitStory(target);
		}

		private void InitStory(UIElement target, Storyboard? storyboard = null, double from = -30, double to = 0)
		{
			storyboard ??= _openStoryBoard;
			DoubleAnimation yd1 = new DoubleAnimation(); //实例化浮点动画
			target.RenderTransform = new RotateTransform(); //设置为旋转动画
			yd1.From = from; //动画的起始值
			yd1.To = to; //动画的结束值
			yd1.Duration = TimeSpan.FromSeconds(0.5); //动画的播放时间
			Storyboard.SetTarget(yd1, target); //给故事板绑定动画
			Storyboard.SetTargetProperty(yd1, new PropertyPath("RenderTransform.Angle")); //动画的依赖属性
			storyboard.Children.Add(yd1); //故事板添加动画
		}

		public void Run()
		{
			_openStoryBoard.Begin(); //播放此动画
		}
	}
}
